package view;

import controller.AddBookListener;
import pojo.Book;

import javax.swing.*;
import java.awt.*;

public class AddBook extends JDialog {
    private JLabel labelId,labelName,labelWriter,labelPage,labelPrice,labelPress,labelClassification,labelSurplus,labelTotal;
    private JTextField tfId,tfName,tfWriter,tfPage,tfPrice,tfPress,tfClassification,tfSurplus,tfTotal;
    private JComboBox cBType;
    private Book book;
    private AddBookListener listener;
    private QueryView queryView;
    public AddBook(QueryView queryView) {
        this.queryView=queryView;
        listener = new AddBookListener(this,queryView);
        this.setTitle("新增图书");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(),BorderLayout.CENTER);
        this.add(this.getButton(),BorderLayout.SOUTH);

    }

    public JPanel getPanel(){
        JPanel jPanel=new JPanel();
        jPanel.setLayout(new GridLayout(8,2));
        labelId=new JLabel("书号");
        labelName=new JLabel("书名");
        labelWriter=new JLabel("作者");
        labelPage=new JLabel("页码");
        labelPrice=new JLabel("价格");
        labelPress=new JLabel("出版社");
        labelClassification=new JLabel("类别");
        labelTotal=new JLabel("总数");
//        labelSurplus=new JLabel("库存");
        tfId=new JTextField(15);
        tfName=new JTextField(15);
        tfWriter=new JTextField(15);
        tfPage=new JTextField(15);
        tfPrice=new JTextField(15);
        tfPress=new JTextField(15);
        cBType=new JComboBox();    //创建JComboBox
        cBType.addItem("--请选择--");    //向下拉列表中添加一项
        cBType.addItem("马列主义毛泽东思想");
        cBType.addItem("哲学");
        cBType.addItem("社会科学");
        cBType.addItem("自然科学");
        cBType.addItem("综合性图书");
        tfTotal=new JTextField(15);
//        tfSurplus=new JTextField(15);
        jPanel.add(labelId);
        jPanel.add(tfId);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelWriter);
        jPanel.add(tfWriter);

        jPanel.add(labelPage);
        jPanel.add(tfPage);

        jPanel.add(labelPrice);
        jPanel.add(tfPrice);

        jPanel.add(labelPress);
        jPanel.add(tfPress);

        jPanel.add(labelClassification);
        jPanel.add(cBType);

        jPanel.add(labelTotal);
        jPanel.add(tfTotal);

//        jPanel.add(labelSurplus);
//        jPanel.add(tfSurplus);

        return jPanel;
    }
    public JPanel getButton(){
        JButton jButton=new JButton("新增");
        JButton jButton1=new JButton("返回");
        jButton.addActionListener(listener);
        jButton1.addActionListener(listener);
        JPanel jPanel=new JPanel();
        jPanel.add(jButton);
        jPanel.add(jButton1);
        return jPanel;
    }

    public JTextField getTfId() {
        return tfId;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfWriter() {
        return tfWriter;
    }

    public JTextField getTfPage() {
        return tfPage;
    }

    public JTextField getTfPrice() {
        return tfPrice;
    }

    public JTextField getTfPress() {
        return tfPress;
    }

    public JTextField getTfClassification() {
        return tfClassification;
    }

    public JTextField getTfSurplus() {
        return tfSurplus;
    }

    public JTextField getTfTotal() {
        return tfTotal;
    }

    public Book getBook() {
        return book;
    }

    public JComboBox getCBType() {
        return cBType;
    }
}

